//
//  NewTuoKeViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2018/3/7.
//  Copyright © 2018年 李 佳伟. All rights reserved.
//

#import "NewTuoKeViewController.h"
#import "JTCSM.h"
#import "HuankuanJiluTableViewCell.h"
#import "NewTuoKeInfoViewController.h"
@interface NewTuoKeViewController ()<UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate,UISearchDisplayDelegate,UITextFieldDelegate,UIAlertViewDelegate>
{
    NSString *mykeyword;
}
@property (nonatomic,strong) NSMutableArray *titlearray;
@property (nonatomic,strong) UISearchBar *mysearchBar;
@property (nonatomic,strong) UITableView *tableview;
@property (nonatomic,strong) UIView *headerView;
@property (nonatomic,strong) UILabel *headerLabel;
@end

@implementation NewTuoKeViewController

- (void)gotBack{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [df isRemoveTarbar:YES];
    self.navigationController.navigationBar.hidden = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    leftBarButtonItems_rightBarButtonItems *leftbtn = KCUSTOMNAVIGSTION_ALLOC;
    self.navigationItem.leftBarButtonItem = [leftbtn setBarButtonItemsImageName:@"fanhui.png" frame:KLeftBarButtonItemFrame_image target:self SEL:@selector(gotBack)];
    // Do any additional setup after loading the view.
    mykeyword = @"";
    [self layoutTableView];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;

}
- (void)layoutTableView{
    
    _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, KCONTROLLERHeight) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    [self.view addSubview:_tableview];
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableview.tableHeaderView = [self layoutheaderView];
    [self setUpTableView];
    //    view.backgroundColor = RGBACOLOR(241, 241, 241, 1);
}

- (UIView *)layoutheaderView {
    self.headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, 84)];
    self.headerView.backgroundColor = RGBACOLOR(241, 241, 241, 1);
    
    self.mysearchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(20, 7, KCONTROLLERWith-40, 30)];
    
    self.mysearchBar.placeholder = @"搜索开户行";
//    self.mysearchBar.searchBarStyle = UISearchBarStyleMinimal;
    [self.mysearchBar setImage:[UIImage imageNamed:@"local"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
    UITextField *searchField = [self.mysearchBar valueForKey:@"_searchField"];
    if (searchField) {
        searchField.frame = CGRectMake(0, 0, CGRectGetWidth(self.mysearchBar.frame),  CGRectGetHeight(self.mysearchBar.frame));
        [searchField setBackgroundColor:[UIColor whiteColor]];
        searchField.layer.cornerRadius = 18.0f;
        searchField.layer.masksToBounds = YES;
    }
    for (UIView *subView in self.mysearchBar.subviews) {
        if ([subView isKindOfClass:[UIView  class]]) {
            [[subView.subviews objectAtIndex:0] removeFromSuperview];
        }
    }
    
    self.mysearchBar.delegate = self;
    [self.headerView addSubview:self.mysearchBar];
    
    UIView *backview = [[UIView alloc]initWithFrame:CGRectMake(0, 44, KCONTROLLERWith, 40)];
    backview.backgroundColor = [UIColor whiteColor];
    [self.headerView addSubview:backview];
    
    self.headerLabel = [UILabel initWithFrame:CGRectMake(20, 0, KCONTROLLERWith-40, 40) text:@"拓客列表32个" font:14 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(153, 153, 153, 1) backgroundColor:nil];
    [backview addSubview:self.headerLabel];
    [df newlineViewWithHeightofTop:84 superView:self.headerView spacing:0 color:RGBACOLOR(241, 241, 241, 1) lineHeight:1];
    
    
    return self.headerView;

}
- (void) searchBarSearchButtonClicked:(UISearchBar *)searchBar

{
    
    mykeyword = searchBar.text;
//    [self theRequestWithKeyWord:mykeyword];
    [searchBar resignFirstResponder];
    
    
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.mysearchBar resignFirstResponder];
    
}
- (void)setUpTableView{
    // 1.下拉刷新(进入刷新状态就会调用self的headerRereshing)
    [_tableview addHeaderWithTarget:self action:@selector(headerRereshing)];
    
    // 上拉加载
    [_tableview addFooterWithTarget:self action:@selector(footerRereshing)];
    
}
- (void)headerRereshing{
    // 2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KRefreshTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //getMarriageSeeking(网络请求)
//        [self theRequestWithKeyWord:mykeyword];
    });
}
- (void)footerRereshing{
    // 2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KRefreshTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //getMarriageSeeking(网络请求)
//        [self loadMoreDataRequestWithKeyWord:mykeyword];
        
    });
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *cellid = [NSString stringWithFormat:@"textfield%ld",(long)indexPath.row];
    HuankuanJiluTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
    if (cell == nil) {
        cell = [[HuankuanJiluTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid cellType:IsDefulatType];
    }
    [cell setValueWithModel:indexPath];
    if (indexPath.row%2==0) {
        cell.stateLabel.textColor = RGBACOLOR(16,161,88, 1);
        cell.stateLabel.text = @"审核通过";
    }else{
        cell.stateLabel.textColor = RGBACOLOR(255,54,54, 1);
        cell.stateLabel.text = @"未完善资料";return cell;
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 75;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NewTuoKeInfoViewController *vc = [[NewTuoKeInfoViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
